"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Implement extends Model {
    //工单模型
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Implement.belongsTo(models.Project, {
        foreignKey: "project_id",
        onDelete: "CASCADE",
      });
      Implement.belongsTo(models.Staff, {
        foreignKey: "implementor_id",
        as: "implementor",
        allowNull: true,
      });
      Implement.belongsTo(models.Staff, {
        foreignKey: "technician_id",
        as: "technician",
      });
      Implement.belongsTo(models.Staff, {
        foreignKey: "checker_id",
        as: "checker",
        allowNull: true,
      });

      // define association here
    }
  }
  Implement.init(
    {
      approval_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      }, // 审核状态

      docs: DataTypes.STRING,
      doc_name: DataTypes.STRING,
      content: DataTypes.TEXT,
      status: DataTypes.STRING, //实施状态
      check_sug: DataTypes.STRING,
      satisfy: DataTypes.STRING,
      people_in_charge: DataTypes.TEXT,
    },
    {
      sequelize,
      modelName: "Implement",
      tableName: "implements",
    }
  );
  return Implement;
};
